/**
 * 游戏等级选择类
 */
package com.key;

import com.key.util.GameParams;
import com.key.util.UserSystemData;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;

public class KeyChineseChessSingleGameActivity extends Activity implements OnClickListener {

	//10个等级按钮
	private ImageButton ButtonOne=null,ButtonTwo=null,ButtonThree=null,ButtonFour=null,ButtonFive=null,
				ButtonSix=null,ButtonSeven=null,ButtonEight=null,ButtonNine=null,ButtonTen=null;
	
	//用户等级
	private int iUserRank = 0;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.key_singlegame_menu);
		
		initView();//初始化界面
		GameParams.singleGameActivity = this;//游戏变量
	}
	
	public void initView() {
		//取得用户等级
		iUserRank = UserSystemData.UserInfo.getUserRank();
		//初始化按钮
		setButtonOne();
		if(iUserRank>1) {
			setButtonTwo(true);
		} else {
			setButtonTwo(false);
		}
		if(iUserRank>2) {
			setButtonThree(true);
		} else {
			setButtonThree(false);
		}
		if(iUserRank>3) {
			setButtonFour(true);
		} else {
			setButtonFour(false);
		}
		if(iUserRank>4) {
			setButtonFive(true);
		} else {
			setButtonFive(false);
		}
		if(iUserRank>5) {
			setButtonSix(true);
		} else {
			setButtonSix(false);
		}
		if(iUserRank>6) {
			setButtonSeven(true);
		} else {
			setButtonSeven(false);
		}
		if(iUserRank>7) {
			setButtonEight(true);
		} else {
			setButtonEight(false);
		}
		if(iUserRank>8) {
			setButtonNine(true);
		} else {
			setButtonNine(false);
		}
		if(iUserRank>9) {
			setButtonTen(true);
		} else {
			setButtonTen(false);
		}
	}
	
	private void setButtonOne() {
		ButtonOne = (ImageButton) findViewById(R.id.degree_1);
		ButtonOne.setBackgroundResource(R.drawable.pass1);
		ButtonOne.setOnClickListener(this);
		ButtonOne.setOnTouchListener(new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					((ImageButton) v).setAlpha(10);
				} else if (event.getAction() == MotionEvent.ACTION_UP) {
					((ImageButton) v).setAlpha(255);
				}
				return false;
			}
		});
	}
	private void setButtonTwo(boolean bType) {
		ButtonTwo = (ImageButton) findViewById(R.id.degree_2);
		if(bType == true) {
			ButtonTwo.setBackgroundResource(R.drawable.pass2);
			ButtonTwo.setOnClickListener(this);
		} else {
			ButtonTwo.setBackgroundResource(R.drawable.nopass2);
		}
	}
	private void setButtonThree(boolean bType) {
		ButtonThree = (ImageButton) findViewById(R.id.degree_3);
		if(bType == true) {
			ButtonThree.setBackgroundResource(R.drawable.pass3);
			ButtonThree.setOnClickListener(this);
		} else {
			ButtonThree.setBackgroundResource(R.drawable.nopass3);
		}
	}
	private void setButtonFour(boolean bType) {
		ButtonFour = (ImageButton) findViewById(R.id.degree_4);
		if(bType == true) {
			ButtonFour.setBackgroundResource(R.drawable.pass4);
			ButtonFour.setOnClickListener(this);
		} else {
			ButtonFour.setBackgroundResource(R.drawable.nopass4);
		}
	}
	private void setButtonFive(boolean bType) {
		ButtonFive = (ImageButton) findViewById(R.id.degree_5);
		if(bType == true) {
			ButtonFive.setBackgroundResource(R.drawable.pass5);
			ButtonFive.setOnClickListener(this);
		} else {
			ButtonFive.setBackgroundResource(R.drawable.nopass5);
		}
	}
	private void setButtonSix(boolean bType) {
		ButtonSix = (ImageButton) findViewById(R.id.degree_6);
		if(bType == true) {
			ButtonSix.setBackgroundResource(R.drawable.pass6);
			ButtonSix.setOnClickListener(this);
		} else {
			ButtonSix.setBackgroundResource(R.drawable.nopass6);
		}
	}
	private void setButtonSeven(boolean bType) {
		ButtonSeven = (ImageButton) findViewById(R.id.degree_7);
		if(bType == true) {
			ButtonSeven.setBackgroundResource(R.drawable.pass7);
			ButtonSeven.setOnClickListener(this);
		} else {
			ButtonSeven.setBackgroundResource(R.drawable.nopass7);
		}
	}
	private void setButtonEight(boolean bType) {
		ButtonEight = (ImageButton) findViewById(R.id.degree_8);
		if(bType == true) {
			ButtonEight.setBackgroundResource(R.drawable.pass8);
			ButtonEight.setOnClickListener(this);
		} else {
			ButtonEight.setBackgroundResource(R.drawable.nopass8);
		}
	}
	private void setButtonNine(boolean bType) {
		ButtonNine = (ImageButton) findViewById(R.id.degree_9);
		if(bType == true) {
			ButtonNine.setBackgroundResource(R.drawable.pass9);
			ButtonNine.setOnClickListener(this);
		} else {
			ButtonNine.setBackgroundResource(R.drawable.nopass9);
		}
	}
	private void setButtonTen(boolean bType) {
		ButtonTen = (ImageButton) findViewById(R.id.degree_10);
		if(bType == true) {
			ButtonTen.setBackgroundResource(R.drawable.pass10);
			ButtonTen.setOnClickListener(this);
		} else {
			ButtonTen.setBackgroundResource(R.drawable.nopass10);
		}
	}

	/**
	 * 点击等级
	 */
	public void onClick(View v) {
		// TODO Auto-generated method stub
			
		Intent gameIntent = null;
		switch (v.getId()) {
		case R.id.degree_1:
			gameIntent = new Intent(this, KeyChineseChessActivity.class);
			putPargms(1);
			this.startActivity(gameIntent);
			break;
		case R.id.degree_2:
			if(iUserRank>1) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(2);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_3:
			if(iUserRank>2) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(3);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_4:
			if(iUserRank>3) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(4);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_5:
			if(iUserRank>4) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(5);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_6:
			if(iUserRank>5) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(6);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_7:
			if(iUserRank>6) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(7);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_8:
			if(iUserRank>7) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(8);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_9:
			if(iUserRank>8) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(9);
				this.startActivity(gameIntent);
			}
			break;
		case R.id.degree_10:
			if(iUserRank>9) {
				gameIntent = new Intent(this, KeyChineseChessActivity.class);
				putPargms(10);
				this.startActivity(gameIntent);
			}
			break;
		default:
			break;
		}
	}
	
	private void putPargms(int id) {
		GameParams.gameLevel = id;
	}
}
